<template>
  <div>

  </div>
</template>


<script>
import {activeRouter} from "@/utils/permission";
import  request from '../../utils/request'

export default {
  name: 'auth-redirect',
  data() {
    return {
      fullscreenLoading: false,
      userId: this.$route.query.userid,
    }
  },
  created() {
     // this.userId = this.$route.query.userid
    console.log("$route:",this.$route)
    this.openFullScreen2()
    console.log("userId:",this.userId)
    if (this.userId) {
      this.authLogin()
    }
  },
  methods: {
    openFullScreen2() {
      const loading = this.$loading({
        lock: true,
        text: '登录成功，正在跳转...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      setTimeout(() => {
        loading.close();
      }, 1000);
    },
    authLogin() {
      console.log("dnakdkjadnka"+this.userId)
      // 根据UerId查询用户信息
      // let userId=sessionStorage.getItem("userid")
      // console.log("<===="+userId)
      request.get('/auth/login/' + this.userId).then( res => {
        console.log("dnakdkjadnka"+this.userId)
        console.log(res)

        if (res.code ==='0') {
          sessionStorage.setItem("user", JSON.stringify(res.data))  // 缓存用户信息
          const permissions=res.data.permissions;
          activeRouter(permissions)
          this.$router.push("/")
        } else {
          this.$message({
            type: "error",
            message: res.msg
          })
        }
      })
    }
  }
}
</script>
